package com.campus.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("操作响应对象")
@Data
public class Result<T> {

    @ApiModelProperty("状态码")
    private Integer code;

    @ApiModelProperty("提示消息")
    private String msg;

    @ApiModelProperty("数据")
    private T data;

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result success(Object data){
        return new Result(200,"操作成功",data);
    }

    public static Result success(){
        return new Result(200,"操作成功",null);
    }

    public static Result success(String msg){
        return new Result(200,msg,null);
    }

    public static Result success(Integer code,String msg,Object data){
        return new Result(code,msg,data);
    }

    public static Result successData(String Data){
        return new Result(200,"操作成功",Data);
    }

    public static Result error(){
        return new Result(500,"操作失败",null);
    }

    public static Result error(String msg){
        return new Result(500,msg,null);
    }

    public static Result error(Integer code,String msg){
        return new Result(code,msg,null);
    }

    public static Result to(boolean rs){
        return rs?success():error();
    }

    public static Result to(int rs){
        return rs >0?success():error();
    }
}
